* BUILDS TABLES IN PAPER

use data2025, clear

* ---> For convenience, rename & label variables here
rename bipman_ev BD
rename bdsib_ev BDSIB
rename depranx_ev DEPRANX
rename schizo_ev SCHIZO
rename earnings EARN
rename totalincome INC
rename disab DISAB
rename female FEMALE
rename birthcohort BIRTHCOHORT
rename year YEAR
rename momid MOMID
rename college COLLEGE 
rename highschool HS 
rename married MARRIED 
rename divorced DIVORCED 


gen MENTAL = DEPRANX == 1 | SCHIZO == 1 | BD == 1 
replace MENTAL = . if DEPRANX == . | SCHIZO == . | BD == . | ANX == .

label var MENTAL 	"MH condition"
label var BD 		"BD"
label var BDSIB 	"BD sibling"
label var DEPRANX 		"Depr/anxiety"
label var SCHIZO 	"Schizophrenia"

* "fix" or create some variables
gen LNEARN = ln(EARN)
replace LNEARN = 0 if LNEARN == .
gen NOEARN = EARN == 0
gen LNINC = ln(INC) 
replace LNINC = 0 if LNINC == .
gen NOINC = INC == 0



* Number of siblings
egen t = tag(PNR MOMID)
bysort MOMID: egen NRSIB = sum(t)
drop t



*************************************************** DATA PREP UNTIL HERE ***************************************************


*************************************************************************************************
*										Main Tables												*
*************************************************************************************************


* Table 2 - Main effects
eststo r1: areg NOEARN BD c.BD#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg NOEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg LNEARN BD c.BD#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT, a(MOMID) cluster(MOMID) 
eststo r4: areg LNEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
esttab r1 r2 r3 r4 using "table2.csv", b(3) se(3) keep(BD c.BD#c.POST MENTAL c.MENTAL#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace

* Table 3 - Siblings
eststo r1: areg NOEARN BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg NOEARN BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg LNEARN BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR if NOEARN == 0, a(BIRTHCOHORT) cluster(MOMID) 
eststo r4: areg LNEARN BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR if NOEARN == 0, a(BIRTHCOHORT) cluster(MOMID) 
esttab r1 r2 r3 r4 using "table3.csv", b(3) se(3)  keep(BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace



* Table 4 - Top and bottom earnings
preserve
keep if NOEARN == 0
eststo r1: areg BOTTOM10 BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum BOTTOM10 if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg BOTTOM10 BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum BOTTOM10 if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg BOTTOM25 BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum BOTTOM25 if e(sample)
estadd scalar ymean = r(mean)
eststo r4: areg BOTTOM25 BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum BOTTOM25 if e(sample)
estadd scalar ymean = r(mean)
eststo r5: areg TOP25 BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum TOP25 if e(sample)
estadd scalar ymean = r(mean)
eststo r6: areg TOP25 BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum TOP25 if e(sample)
estadd scalar ymean = r(mean)
eststo r7: areg TOP10 10 c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum TOP10 if e(sample)
estadd scalar ymean = r(mean)
eststo r8: areg TOP10 10 c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum TOP10 if e(sample)
estadd scalar ymean = r(mean)
esttab r1 r2 r3 r4 r5 r6 r7 r8 using "table4.csv", b(3) se(3) keep(BD c.BD#c.POST MENTAL c.MENTAL#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace
restore

* Table 5 - Disability and total income
eststo r1: areg DISAB BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum DISAB if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg DISAB BD c.BD#c.POST BDSIB c.BDSIB#c.POST FEMALE MENTAL MENTAL_POST c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR, a(BIRTHCOHORT) cluster(MOMID) 
sum DISAB if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg LNINC BD c.BD#c.POST BDSIB c.BDSIB#c.POST DEPRANX SCHIZO FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR if NOINC == 0, a(BIRTHCOHORT) cluster(MOMID) 
eststo r4: areg LNINC BD c.BD#c.POST BDSIB c.BDSIB#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR if NOINC == 0, a(BIRTHCOHORT) cluster(MOMID) 
esttab r1 r2 r3 r4 using "table5.csv", b(3) se(3) keep(BD c.BD#c.POST MENTAL c.MENTAL#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace


* Table 6 - Results by gender -- RERUN
eststo r1: areg NOEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST i.YEAR i.BIRTHCOHORT if FEMALE == 0, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg NOEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST i.YEAR i.BIRTHCOHORT if FEMALE == 1, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg NOEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#c.BD c.FEMALE#c.BD#c.POST c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r4: areg LNEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST i.YEAR i.BIRTHCOHORT if FEMALE == 0 if NOEARN == 0, a(MOMID) cluster(MOMID) 
eststo r5: areg LNEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST i.YEAR i.BIRTHCOHORT if FEMALE == 1 if NOEARN == 0, a(MOMID) cluster(MOMID) 
eststo r6: areg LNEARN BD c.BD#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#.BD c.FEMALE#.BD#c.POST c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) 
esttab r1 r2 r3 r4 r5 r6 using "table6.csv", b(3) se(3) keep(BD c.BD#c.POST c.FEMALE#.BD c.FEMALE#.BD#c.POST MENTAL c.MENTAL#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace


* Table 7 - Results by Wealth


global wealthdiff = "TOPWEALTH MIDWEALTH BOTTOMWEALTH c.BD#c.BOTTOMWEALTH c.BD#c.MIDWEALTH c.BD#c.TOPWEALTH c.BD#c.POST#c.BOTTOMWEALTH c.BD#c.POST#c.MIDWEALTH c.POST#c.BOTTOMWEALTH c.BD#c.POST#c.TOPWEALTH c.POST#c.TOPWEALTH"


eststo r1: areg NOEARN BD c.BD#c.POST $wealthdiff DEPRANX SCHIZO FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg NOEARN BD c.BD#c.POST $wealthdiff DEPRANX SCHIZO FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT , a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg LNEARN BD c.BD#c.POST $wealthdiff MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
eststo r4: areg LNEARN BD c.BD#c.POST $wealthdiff MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
esttab r1 r2 r3 r4 using "table7.csv", b(3) se(3) keep(BD c.BD#c.POST $wealthdiff) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace


* Table 8 - Results by intensity of the condition
eststo r1: areg NOEARN BD c.BD#c.POST BDEPISODES c.BDEPISODES#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r2: areg NOEARN BD c.BD#c.POST BDEPISODES c.BDEPISODES#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
sum NOEARN if e(sample)
estadd scalar ymean = r(mean)
eststo r3: areg LNEARN BD c.BD#c.POST BDEPISODES c.BDEPISODES#c.POST FEMALE DEPRANX SCHIZO c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0, a(MOMID) cluster(MOMID) 
eststo r4: areg LNEARN BD c.BD#c.POST BDEPISODES c.BDEPISODES#c.POST MENTAL c.MENTAL#c.POST FEMALE c.FEMALE#i.YEAR c.FEMALE#i.BIRTHCOHORT i.YEAR i.BIRTHCOHORT if NOEARN == 0 if NOEARN == 0, a(MOMID) cluster(MOMID) 
esttab r1 r2 r3 r4 using "table8.csv", b(3) se(3) keep(BD c.BD#c.POST BDEPISODES c.BDEPISODES#c.POST) stats(ymean N N_clust r2, fmt(3 0 0 2)) starlevel(* .1 ** .05 *** .01) replace


